define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layui'], function ($, undefined, Backend, Table, Form, layui) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'feature/index' + location.search,
                    add_url: 'feature/add',
                    edit_url: 'feature/edit',
                    del_url: 'feature/del',
                    multi_url: 'feature/multi',
                    import_url: 'feature/import',
                    table: 'feature',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'feature_name', title: __('Feature_name'), operate: 'LIKE'},
                        {field: 'color', title: __('Color'), operate: 'LIKE'},
                        {field: 'iconimage', title: __('Iconimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search: false,
                commonSearch: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            layui.use('colorpicker', function () {
                var $ = layui.$
                    , colorpicker = layui.colorpicker;
                colorpicker.render({
                    elem: '#color-form',
                    color: '#1c97f5',
                    done: function (color) {
                        $('#c-color').val(color);
                    }
                })
            });
            Controller.api.bindevent();
        },
        edit: function () {
            let editcolor = $('input[name="row[color]"]').val()
            layui.use('colorpicker', function () {
                var $ = layui.$
                    , colorpicker = layui.colorpicker;
                colorpicker.render({
                    elem: '#color-form',
                    color: editcolor,
                    done: function (color) {
                        $('#c-color').val(color);
                    }
                })
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
